Zepto(function($) {
  window.onload=function () {
    initView();
  }
  function initView() {
    console.log(headers("memberCoupn.selectCouponList"));
    $.ajax({
      type: 'GET',
      url: getUrl + '/wxmall/member/coupn/selectCouponList',
      data: {},
      dataType: 'json',
      timeout: 15000,
      headers: headers("memberCoupn.selectCouponList"),
      // contentType:'application/json',
      success: function(data){
        callbackss(data);
      },
      error: function(xhr, type){
      }
    });
  }
  function callbackss(data) {
    $("#noUser").html("");
    $("#willUser").html("");
    $("#yetUser").html("");
    if(!data.success){
      return
    }
    console.log(data);
    var data1 = data.data;
    var table1 = document.body.querySelector('#noUser');
    var table2 = document.body.querySelector('#willUser');
    var table3 = document.body.querySelector('#yetUser');
    var table4 = document.body.querySelector('#yetused');
    if(data1.length == 0){
      return
    }
    for(var i = 0 ; i < data1.length ; i++){
      var conditions = "";
      if(data1[i].conditions != null && data1[i].conditions != undefined){
        conditions = data1[i].conditions;
      }
      var amout = "";
      if(data1[i].amout != null && data1[i].amout != undefined){
        amout = data1[i].amout;
      }
      var startTime = "";
      if(data1[i].startTime != null && data1[i].startTime != undefined){
        startTime = data1[i].startTime.substring(0,10);
      }
      var endTime = "";
      if(data1[i].endTime != null && data1[i].endTime != undefined){
        endTime = data1[i].endTime.substring(0,10);
      }
      if(data1[i].state == "未使用"){
        var li = document.createElement("li");
        li.innerHTML='<div class="topPopover">\n' +
            '                        <div class="use-date">使用日期</div>\n' +
            '                        <div class="use-date">2017.08.30 12:30</div>\n' +
            '                        <div class="but-delete">删除</div>\n' +
            '                    </div>'+
            '<div class="discount-value">' +
            '                        <p><span class="unit">￥</span><span class="value">'+amout+'</span></p>' +
            '                        <div>'+conditions+'</div>' +
            '                    </div>' +
            '                    <div class="user-type">' +
            '                        <p>全场使用</p>' +
            '                        <div>' + startTime + '至' + endTime + '</div>' +
            '                    </div>' +
            '                    <div class="specifica-goods">' +
            '                        <div>去下单</div>' +
            '                    </div>';
        table1.appendChild(li);
      }
      if(data1[i].state == "已失效"){
        var li = document.createElement("li");
        li.innerHTML='<div class="topPopover">\n' +
            '                        <div class="use-date">使用日期</div>\n' +
            '                        <div class="use-date">2017.08.30 12:30</div>\n' +
            '                        <div class="but-delete">删除</div>\n' +
            '                    </div>'+
            '<div class="discount-value">' +
            '                        <p><span class="unit">￥</span><span class="value">'+amout+'</span></p>' +
            '                        <div>'+conditions+'</div>' +
            '                    </div>' +
            '                    <div class="user-type">' +
            '                        <p>全场使用</p>' +
            '                        <div>' + startTime + '至' + endTime + '</div>' +
            '                    </div>' +
            '                    <div class="specifica-goods">' +
            '                        <div>已过期</div>' +
            '                    </div>';
        table3.appendChild(li);
      }
      if(data1[i].state == "即将过期"){
        var li = document.createElement("li");
        li.innerHTML='<div class="topPopover">\n' +
            '                        <div class="use-date">使用日期</div>\n' +
            '                        <div class="use-date">2017.08.30 12:30</div>\n' +
            '                        <div class="but-delete">删除</div>\n' +
            '                    </div>'+
            '<div class="discount-value">' +
            '                        <p><span class="unit">￥</span><span class="value">'+amout+'</span></p>' +
            '                        <div>'+conditions+'</div>' +
            '                    </div>' +
            '                    <div class="user-type">' +
            '                        <p>全场使用</p>' +
            '                        <div>' + startTime + '至' + endTime + '</div>' +
            '                    </div>' +
            '                    <div class="specifica-goods">' +
            '                        <div>去下单</div>' +
            '                    </div>';
        table2.appendChild(li);
      }
    }
    if(data1[0].state == "已使用"){
      var li = document.createElement("li");
      li.innerHTML='<div class="topPopover">\n' +
          '                        <div class="use-date">使用日期</div>\n' +
          '                        <div class="use-date">2017.08.30 12:30</div>\n' +
          '                        <div class="but-delete">删除</div>\n' +
          '                    </div>'+
          '<div class="discount-value">' +
          '                        <p><span class="unit">￥</span><span class="value">'+amout+'</span></p>' +
          '                        <div>'+conditions+'</div>' +
          '                    </div>' +
          '                    <div class="user-type">' +
          '                        <p>全场使用</p>' +
          '                        <div>' + startTime + '至' + endTime + '</div>' +
          '                    </div>' +
          '                    <div class="specifica-goods">' +
          '                        <div>已过期</div>' +
          '                    </div>';
      table4.appendChild(li);
    }
  }
  /**
   * 返回上一页
   *
   */
  $(".nav-header").on("click",".back",function (e) {
    window.history.go(-1);
  });
  $(".tab").on("click","div",function () {
    $(".tab>div").removeClass("active");
    $(this).addClass('active');
  });
  $(".tab").on("click",".tab1",function () {
    $(".tab1-cont").css("display","block");
    $(".tab2-cont").css("display","none");
    $(".tab3-cont").css("display","none");
    $(".tab4-cont").css("display","none");
    $("title").html("未使用");
  });
  $(".tab").on("click",".tab2",function () {
    $("title").html("即将过期");
    $(".tab1-cont").css("display","none")
    $(".tab2-cont").css("display","block")
    $(".tab3-cont").css("display","none")
    $(".tab4-cont").css("display","none");
  });
  $(".tab").on("click",".tab3",function () {
    $(".tab1-cont").css("display","none");
    $(".tab2-cont").css("display","none");
    $(".tab3-cont").css("display","block");
    $(".tab4-cont").css("display","none");
    $("title").html("已失效");
  });
  $(".tab").on("click",".tab4",function () {
    $(".tab1-cont").css("display","none");
    $(".tab2-cont").css("display","none");
    $(".tab3-cont").css("display","none");
    $(".tab4-cont").css("display","block");
    $("title").html("已使用");
  });
  var time = 0;
  $("body").on("touchstart","li",function(e) {
    e.stopPropagation();
    $($(this)[0]).css("box-shadow","0 0 2px #000 inset");
    var index = $($(this).find(".topPopover")[0]);
    time = setTimeout(function(){
      index.css("display","block");
    }, 1000);
  });
  /**
   *
   *box-shadow:0 0 1px #000 inset;
   */
  $("body").on('touchend', 'li', function(e){
    $($(this)[0]).css("box-shadow","0 0 0px #000 inset");
    e.stopPropagation();
    clearTimeout(time);
  });
  function toppopur(e) {
    // var topPopover = document.createElement("div");
    // topPopover.className="topPopover";
    // topPopover.innerHTML=""
    // e.appendChild();
  }
});